package cn.pw.test.com.conversion.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;

import java.util.ArrayList;

import cn.pw.test.com.conversion.R;
import cn.pw.test.com.conversion.adapter.FragmentAdapter;
import cn.pw.test.com.conversion.fragment.ConversionBeanOilFragment;
import cn.pw.test.com.conversion.fragment.ConversionBeansFragment;
import cn.pw.test.com.conversion.fragment.ConversionCrudeFragment;
import cn.pw.test.com.conversion.fragment.ConversionGoldFragment;
import cn.pw.test.com.conversion.fragment.ConversionRubberFragment;
import cn.pw.test.com.conversion.manager.ConversionPathManager;
import tech.com.commoncore.base.BaseTitleActivity;

@Route(path = ConversionPathManager.CONVERSION_CONVERSION)
public class ConversionActivity extends BaseTitleActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private FragmentAdapter fragmentAdapter;

    private String[] title;
    private ArrayList<Fragment> fragments;

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText(R.string.conversion_string_title);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_conversion;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        tabLayout = findViewById(R.id.conversion_tab_layout);
        viewPager = findViewById(R.id.conversion_view_pager);

        title = new String[]{
                getString(R.string.conversion_string_crude),
                getString(R.string.conversion_string_gold),
                getString(R.string.conversion_string_BeanOil),
                getString(R.string.conversion_string_beans),
                getString(R.string.conversion_string_rubber)};

        fragments = new ArrayList<>();
        fragments.add(ConversionCrudeFragment.newInstance());
        fragments.add(ConversionGoldFragment.newInstance());
        fragments.add(ConversionBeanOilFragment.newInstance());
        fragments.add(ConversionBeansFragment.newInstance());
        fragments.add(ConversionRubberFragment.newInstance());
//        fragments.add(ConversionWheatFragment.newInstance());
//        fragments.add(ConversionCottonFragment.newInstance());

        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments, title);
        viewPager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(viewPager);

        int position = getIntent().getIntExtra("conversionKey", 0);
        viewPager.setCurrentItem(position);
    }
}
